class ColegiosController < ApplicationController
  
  def initialize
    @cidades = City.find :all
    @tiposcolegios = Colegiotype.find :all
  end

  # GET /colegios
  # GET /colegios.xml
  def index
    @colegios = Colegio.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @colegios }
    end
  end

  # GET /colegios/1
  # GET /colegios/1.xml
  def show
    @colegio = Colegio.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @colegio }
    end
  end

  # GET /colegios/new
  # GET /colegios/new.xml
  def new
    @colegio = Colegio.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @colegio }
    end
  end

  # GET /colegios/1/edit
  def edit
    @colegio = Colegio.find(params[:id])
  end

  # POST /colegios
  # POST /colegios.xml
  def create
    @colegio = Colegio.new(params[:colegio])

    @colegio = modifica @colegio,params[:colegio]

    respond_to do |format|
      if @colegio.save
        flash[:notice] = 'Colegio was successfully created.'
        format.html { redirect_to(@colegio) }
        format.xml  { render :xml => @colegio, :status => :created, :location => @colegio }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @colegio.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /colegios/1
  # PUT /colegios/1.xml
  def update
    @colegio = Colegio.find(params[:id])

    respond_to do |format|
      if @colegio.update_attributes(params[:colegio])
        flash[:notice] = 'Colegio was successfully updated.'
        format.html { redirect_to(colegios_url) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @colegio.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /colegios/1
  # DELETE /colegios/1.xml
  def destroy
    @colegio = Colegio.find(params[:id])
    @colegio.destroy

    respond_to do |format|
      format.html { redirect_to(colegios_url) }
      format.xml  { head :ok }
    end
  end
end
